1 00:00:01,890 --> 00:00:06,390 Okay, So in this lecture, we're going to be taking a look at collision groups. 2 00:00:06,420 --> 00:00:11,850 Now, collision groups allow us to manipulate how parts collide with other parts, meaning we can set 3 00:00:11,850 --> 00:00:16,770 a part to be able to pass through one wall, but it won't be able to pass through another wall. 4 00:00:16,890 --> 00:00:21,870 We can set the collision group of apart in studio using their collision group property, or we can do 5 00:00:21,870 --> 00:00:23,250 it from scripts as well. 6 00:00:23,580 --> 00:00:27,090 I have my neat little setup here to show you how collision groups work. 7 00:00:27,240 --> 00:00:31,830 So we can go to the model tab and open up the Collision Group menu. 8 00:00:32,790 --> 00:00:35,790 And here at the top we can hit this add group button. 9 00:00:35,790 --> 00:00:37,230 And let's name our new group. 10 00:00:37,230 --> 00:00:38,940 I'll just call this one ball. 11 00:00:40,360 --> 00:00:45,370 And in here I can select which groups I want the ball group to collide or not collide with. 12 00:00:46,650 --> 00:00:48,060 I'm going to create another group. 13 00:00:48,060 --> 00:00:50,970 I'm going to call this one passable wall. 14 00:00:52,530 --> 00:00:55,950 And I don't want the ball group to collide with the passable wall group. 15 00:00:55,950 --> 00:01:01,980 So I'll uncheck this here, and I'm going to select the two parts that I want to be part of my ball 16 00:01:01,980 --> 00:01:06,330 collision group, and then I can hit this plus button here. 17 00:01:06,630 --> 00:01:09,460 And I have added these balls to the collision group. 18 00:01:09,480 --> 00:01:11,910 You see it updated down here in the properties menu. 19 00:01:12,240 --> 00:01:17,580 And for these walls down here, I just want the green one to be part of my passable wall collision group. 20 00:01:17,580 --> 00:01:19,620 So I'll hit the plus button here. 21 00:01:20,130 --> 00:01:22,410 The collision group property got updated. 22 00:01:23,950 --> 00:01:29,050 And now this means that these two balls, one of these will hit this wall and not go through. 23 00:01:29,050 --> 00:01:31,940 But this one right here will go straight through this wall. 24 00:01:31,960 --> 00:01:35,230 So to show this, I'll run my game. 25 00:01:36,770 --> 00:01:38,090 And there we go. 26 00:01:38,570 --> 00:01:42,200 This one got stopped by this wall, but this one kept going straight through. 27 00:01:42,560 --> 00:01:46,510 And we can also change how these balls interact with each other. 28 00:01:46,520 --> 00:01:52,010 So back in my Collision group menu, I can actually disable the collisions with each other. 29 00:01:52,970 --> 00:01:57,530 So that means if any of these two balls were to end up meeting each other, they would go straight through 30 00:01:57,530 --> 00:01:58,220 each other. 31 00:01:58,580 --> 00:02:03,920 As an example, I'll just duplicate this one and place it slightly below it in front of it. 32 00:02:04,370 --> 00:02:06,650 And then if I run my game again. 33 00:02:08,570 --> 00:02:10,550 You see, they pass right through each other. 34 00:02:11,560 --> 00:02:14,920 And I can also update coalition groups from scripts as well. 35 00:02:15,370 --> 00:02:20,950 So if I go into the server script service, I'm going to add a new script in here. 36 00:02:21,400 --> 00:02:26,770 And from the script, I'm going to access something called the Physics Service, and I'll store it in 37 00:02:26,770 --> 00:02:27,820 a variable. 38 00:02:31,460 --> 00:02:32,510 His ex service. 39 00:02:33,640 --> 00:02:39,460 And maybe I want to change the collision group of all the parts that make up a character of a player 40 00:02:39,460 --> 00:02:40,270 in my game. 41 00:02:40,570 --> 00:02:45,490 So I'll just do game players, Dot player added. 42 00:02:46,090 --> 00:02:51,940 Connect a function to this, get the player and then when the player gets a character added to them, 43 00:02:52,210 --> 00:02:58,060 we'll connect another function to that event, get a character, and then we're going to loop through 44 00:02:58,060 --> 00:02:59,200 every single part. 45 00:03:00,490 --> 00:03:01,750 And the character. 46 00:03:06,010 --> 00:03:07,330 And if it is a. 47 00:03:08,490 --> 00:03:09,420 Base part. 48 00:03:11,560 --> 00:03:16,120 Then what we can do is we can get the parts collision. 49 00:03:18,190 --> 00:03:21,550 Group property and we'll set it to. 50 00:03:22,400 --> 00:03:24,890 Maybe we'll set it to the ball collision group. 51 00:03:24,920 --> 00:03:25,580 Why not? 52 00:03:26,030 --> 00:03:32,480 And from the script, I can use the physics service to access functions like Collision Group, set, 53 00:03:32,480 --> 00:03:38,390 Collide table, or check if two collision groups are collectable or rename a collision group. 54 00:03:38,420 --> 00:03:46,550 So if I do this function here, I'll pass the name of like passable wall and then I'll pass the name 55 00:03:46,550 --> 00:03:48,530 of the default collision group. 56 00:03:49,760 --> 00:03:54,860 And these two collision groups all set to false meaning they will no longer collide with each other. 57 00:03:54,890 --> 00:03:57,590 So now if I go to play, test my game. 58 00:04:00,100 --> 00:04:01,660 I spawn in my character. 59 00:04:03,820 --> 00:04:06,640 Should be part of the ball collision group. 60 00:04:13,910 --> 00:04:14,570 That's a little strange. 61 00:04:14,570 --> 00:04:15,740 It's not updated here. 62 00:04:16,070 --> 00:04:19,820 Well, I can tell I'm part of the ball collision group because I'm able to pass straight through the 63 00:04:19,820 --> 00:04:20,090 slot. 64 00:04:20,090 --> 00:04:20,930 Looks like it's just. 65 00:04:21,930 --> 00:04:24,360 Has it been updated here in this collision group property? 66 00:04:24,360 --> 00:04:25,200 But that's fine. 67 00:04:26,220 --> 00:04:32,310 I am totally able to pass right through this wall and because in the script I have made passable walls 68 00:04:32,310 --> 00:04:35,700 and the default collision group non collided with each other. 69 00:04:35,910 --> 00:04:38,190 That means if I ran my game. 70 00:04:39,460 --> 00:04:41,140 And then I were to. 71 00:04:42,410 --> 00:04:46,430 Access this part right here that for some reason I can't access. 72 00:04:48,400 --> 00:04:52,210 If I were to un anchor it, it should fall straight through the map. 73 00:04:52,660 --> 00:04:53,280 Yep. 74 00:04:53,290 --> 00:04:54,010 There we go. 75 00:04:55,750 --> 00:04:58,360 So that's all about coalition groups.